<template>
  <div class="nextCore">
    <div v-if="isEditModel && showNextList.includes(category) && taskObj.isNextPerson">
      <a-row>
        <a-col :span="2"> 下一步处理人： </a-col>
        <a-col :span="8">
          <!-- 下一步处理人选择 -->
          <CANDIDATA ref="candidataRef" :f_nextList="processNext.next" @f_setTaskVariable="s_setTaskVariable" />
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
import { findBehindTaskExecuser } from '@/api/workflow/mf_MyTaskUndo.js'
import { saveVariable } from '@/api/workflow/wf_MyStartInstance.js'
import { showNextList } from '@/enumeration/Tp_category.js'
export default {
  props: {
    taskid: {
      type: String,
      required: true,
    },
    processinstanceid: {
      type: String,
      required: true,
    },
    category: {
      type: String,
      default: '',
    },
    isEditModel: {
      // 是否是编辑模式
      type: Boolean,
      default: false,
      required: true,
    },
  },
  data() {
    return {
      showNextList: showNextList, // 需要显示下一步的环节
      processNext: null,
      taskObj: {
        isNextPerson: false, // 是否需要或指定下一步的处理人 和
        isNextComplete: false, // 是否完成下一步处理人的指定
        taskVariab: {}, // 下一步处理人流程变量对象
      },
    }
  },
  created() {
    if (this.isEditModel && this.showNextList.includes(this.category)) {
      this.getFindBehindTaskExecuser()
    }
  },
  methods: {
    // 下一步处理人回显
    s_setTaskVariable(data) {
      console.log('下一步处理人赋值222', data)
      if (data) {
        saveVariable(this.processinstanceid, data).then((res) => {
          // this.$message.success('设置成功')
        })
      }
    },
    // 下一环节的处理人信息
    getFindBehindTaskExecuser() {
      this.processNext = null
      findBehindTaskExecuser({
        taskid: this.taskid,
        direction: 1,
      }).then((res) => {
        if (res.code === 0) {
          // console.log('下个环节信息', res)
          this.processNext = res.data || []
          if (this.processNext.exist) {
            this.processNext.next.forEach((v) => {
              v.assignee.forEach((assignee) => {
                if (assignee.indexOf('$') > -1) {
                  this.taskObj.isNextPerson = true
                }
              })
            })
          }
        }
      })
    },
  },
  components: {
    CANDIDATA: () => import('@/views/workflow/Wf_candidata.vue'),
  },
}
</script>

<style lang="less" scoped>
.nextCore {
  // border: 1px solid red;
  padding: 0 20px 20px 20px;
  // font-size: 16px;
  color: #262626;
}
</style>
